package com.sitanyun.merchant.guide.base;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.sitanyun.merchant.guide.R;


/**
 * ProgressDialog
 * 加载圈
 *
 * @author lz
 * @date 2019/9/17
 */

public class ProgressDialog extends Dialog {

    TextView hintTV;

    public ProgressDialog(Context context) {
        super(context, R.style.progress_dialog);
        init(context);
    }

    public ProgressDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    protected ProgressDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    private void init(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.progress_dialog_layout, null);
        this.setContentView(view);
        hintTV = (TextView) view.findViewById(R.id.progress_dialog_tv_hint);

        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
//        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
        layoutParams.gravity = Gravity.CENTER;
//        layoutParams.width = (int) (d.widthPixels * 0.7); // 高度设置为屏幕的0.7
//        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
//        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
        setCanceledOnTouchOutside(false);
        setCancelable(true);

    }

    public ProgressDialog setHint(String hint) {
        hintTV.setText(hint);
        return this;
    }

    public void show(String msg) {
        hintTV.setText(msg);
        if (!this.isShowing()) {
            show();
        }
    }
}
